<#macro uploadButton fileAccept fileMaxSize btnId btnTxt htmlContentId varName templateHtml>
	<style>
	.el-button_${(btnId)!}{
		width: 100px;
    	height: 35px;
    	border-radius: 5px;
    	cursor: pointer;
	}
	</style>
	<script type="text/template" id="file-temp-item-tpl${(htmlContentId)!}">
		${(templateHtml)!}
	</script>
	
	<input type="file" <#if fileAccept??>accept="${(fileAccept)!}"</#if> name="fileTest[]" style="display: none;" id="uploadFileButton${(htmlContentId)!}" multiple/>
	<input type="button" class="el-button_${(btnId)!}" id="${(btnId)!'selectBtn'}" onclick="$('#uploadFileButton${(htmlContentId)!}').click()" value="${(btnTxt)!'选择文件'}" />
	
	<script>
	    var isExistFiles = [];
		// 保存当前选择的（更新后）文件列表
		var curFiles${(varName)!} = [];
		// 初始选择文件时触发
		$('#uploadFileButton${(htmlContentId)!}').change(function() {
			var $this = $(this),
				files = this.files;
			<#if fileMaxSize?? >
			if(!fileSizeMax(files))
			{
				$.alert("文件大小不能超过" + ${fileMaxSize} + "M!");
				return;
			}
			</#if>
			if(files && files.length) {
				// 原始FileList对象不可更改，所以将其赋予curFiles${(varName)!}提供接下来的修改
				addItem(files);
				$("#uploadFileButton${(htmlContentId)!}").val(""); 
			}
			//console.log(curFiles${(varName)!});
		});

		function addItem(curFiles) {
			var temps =[];
			var htmlContent = $('#file-temp-item-tpl${(htmlContentId)!}').html();
			//console.log("be===");
			//console.log(isExistFiles);
			for(var i = 0, len = curFiles.length; i < len; i++) {
				if(isExistFiles.indexOf(curFiles[i].name) < 0) {
					var html = htmlContent.replaceAll("{{fileName}}",curFiles[i].name);
					$('#${(htmlContentId)!}').prepend(html);
					isExistFiles.push(curFiles[i].name);
					temps.push(curFiles[i]);
				} 
			}
			if(temps.length > 0) {
				Array.prototype.push.apply(curFiles${(varName)!}, temps);
			}
			//console.log("ok===");
			//console.log(isExistFiles);
		}
		
		function fileSizeMax(curFiles) {
			for(var i = 0, len = curFiles.length; i < len; i++) {
				var size = curFiles[i].size / 1024;    
      			if(size> (${(fileMaxSize)!} * 1024)) {
      				return false;
      			}
			}
      		return true;
		}

		function delFile(obj, filename) {
			curFiles${(varName)!} = curFiles${(varName)!}.filter(function(file) {
				return file.name !== filename;
			});
			var newExistFiles = [];
			$.each(isExistFiles,function(index,value){
     			if(value !== filename) {
     				newExistFiles.push(value);
     				//console.log(value);
     			}
			});
			isExistFiles = newExistFiles;
			////console.log(curFiles${(varName)!});
			//console.log(isExistFiles);
			//addItem(curFiles${(varName)!});
		}
	</script>
</#macro>